/**
 * Created by evantang on 4/21/17.
 */
import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {WECHAT_SERVER_URL} from "../constants";
import {Headers} from "@angular/http";

@Injectable()
export class JsSdkService {

    constructor(private http: HttpClient) {
    }

    getServiceUrl(): string {
        return WECHAT_SERVER_URL;
    }

    getSignature(url: string) {
        return this.http.get<any>(this.getServiceUrl() + '/signature?url=' + url);
    }

    getAddressIP() {
        return this.http.get('http://freegeoip.net/json/?callback=?');
    }

    getAccessToken(code) {
      return this.http.get<any>('https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx01ad0d700af56f26&secret=87f6a972e47ee424d299970ce727ee60&code=' + code + '&grant_type=authorization_code');
    }

    getImage(code) {
      return this.http.get<any>('http://114.55.38.236:9801/qrcode?scene_id=' + code);
    }

    configJS() {
      return this.http.get(`https://wechat.fuyitianjian.net/wechat/config.js?api=scanQRCode`, { responseType: 'text'});
    }
}
